home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 908 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.4 KB  |  70 lines

  1. Path: chronicle.mti.sgi.com!austern
  2. From: jarausch@igpm.rwth-aachen.de (Helmut Jarausch)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Rationale behind disallowal of non-const r
  5. Date: 29 Mar 1996 09:07:33 PST
  6. Organization: RWTH Aachen (Inst. f. Geometrie & Prakt. Mathematik)
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4jgukv$dcg@news.rwth-aachen.de>
  9. References: <DAVEW.96Mar27195129@trigati.cs.haverford.edu> <4jevb1$kkp@engnews1.Eng.Sun.COM>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 29 Mar 1996 15:12:31 GMT
  12. X-Newsreader: xrn 7.00 (Motif)
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMVwY1ky4NqrwXLNJAQFEQAH9FCkwlnJ9NWFUECmobeqwrGx5EynPYM6P
  15.     CCWk4jjfq0VtCLx7Sac1pX9DlxGT+RPhFZ8bp77A+W3z4HlZeX6Rzw==
  16.     =6ePO
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article <4jevb1$kkp@engnews1.Eng.Sun.COM>, clamage@Eng.sun.com (Steve
  20. Clamage) writes:
  21. > In article 96Mar27195129@trigati.cs.haverford.edu,
  22. > davew@trigati.cs.haverford.edu (David G. Wonnacott) writes:
  23. > >
  24. > >I am looking for an explanation for the rationale behind the decision
  25. > >of the standards committee to disallow the binding of a non-const
  26. > >reference to an rvalue.
  27.  
  28. SNIP
  29.  
  30.  
  31.  
  32. > Yes, there are times when you would like to be able to bind an rvalue
  33. > to a non-const reference, since the only things you care about are
  34. > sure to happen anyway. For example, given a class T:
  35. >     T f1();     // f1 returns a T rvalue
  36. >     f1().foo(); // ok only if foo is a const member function of T
  37. > Sometimes you don't care about the effects of foo on the object here,
  38. > and you only want the external side-effects of foo. I believe the C++
  39. > committee looked for ways to allow this binding of an rvalue to a non-const
  40. > reference in cases where the results were what was intended, but failed to
  41. > find a good way to define those cases.
  42.  
  43. What about the following rule
  44.  
  45. class T
  46. {
  47.   change() { ...};
  48.   lookat() { ...} const;
  49. }
  50.  
  51.       T f1(){ ...};
  52. const T f2(){...};
  53.  
  54. f1().change(); // should be OK
  55. f2().change(); // should be an error
  56. f2().lookat(); // should be OK
  57.  
  58. Helmut Jarausch
  59. Institute of Technology
  60. RWTH-Aachen
  61. Germany
  62. ---
  63. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  64.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  65.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  66.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  67.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  68. ]
  69.